# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface



#
# class SipderworkscrapyPipeline:
#     def process_item(self, item, spider):
#         pass


# 使用mysql存储招聘数据
from sipderWorkScrapy.Model import JobsInfo


class JobsInfoPipline:
    def __init__(self):
        pass

    def close_spider(self, spider):
        pass

    def process_item(self, item, spider):
        try:
            job_info = JobsInfo()
            job_info.job_name = item['job_name']
            job_info.job_salary = item['job_salary']
            job_info.job_place = item['job_place']
            job_info.job_experience = item['job_experience']
            job_info.job_education = item['job_education']
            job_info.job_tag = item['job_tag']
            job_info.company_name = item['company_name']
            job_info.company_type = item['company_type']
            job_info.company_scale = item['company_scale']
            job_info.link = item['link']
            job_info.save()
            print(f"{item['job_name']}保存成功")
        except (IndexError, TypeError, TimeoutError):
            print("保存失败")
        # print("item", item)
